﻿using System;
using System.Diagnostics;

namespace Simp.Model.CoreExpressions
{
	/// <summary>Simplifies into an addition of the left operand and the negative of the right operand.</summary>
	[ExpressionName("Substraction")]
	[ParameterPolicy("left", "right")]
	[DebuggerDisplay("{ExpressionHelper.Serialize(this)}")]
	public class SubstractionExpression : IExpression, ISimplifiableExpression
	{
		#region ISimplifiableExpression Members
		IExpression ISimplifiableExpression.Simplify(SimplificationMode simplificationMode, params IExpression[] parameterList)
		{
			if (parameterList == null)
			{
				throw new ArgumentNullException("parameterList");
			}
			if (parameterList.Length == 2)
			{
				IExpression leftExpression = parameterList[0];
				IExpression rightExpression = parameterList[1];
				IExpression negativeRightExpression = new CompositeExpression(new NegativerExpression(), rightExpression);
				IExpression additionExpression =
					new CompositeExpression(new AdditionExpression(), leftExpression, negativeRightExpression);

				return ExpressionHelper.Simplify(false, additionExpression, simplificationMode);
			}
			else
			{
				return null;
			}
		}
		#endregion
	}
}